package com.itheima.controller;

import com.itheima.dto.CheckGroupDto;
import com.itheima.entry.PageResult;
import com.itheima.entry.QueryPageBean;
import com.itheima.entry.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jshstart
 * @creat 2020-11-11 15:25
 */
@RequestMapping("/CheckGroup")
@RestController
public class CheckGroupController {
    @Reference
    private CheckGroupService checkGroupService;
//  第一种添加方式
//    @PostMapping("addGroup")
//    public Result addGroup(@RequestBody CheckGroup checkGroup){
//        System.out.println(checkGroup.getCheckitemIds());
//        System.out.println("checkGroup = " + checkGroup);
//        checkGroupService.addGroup(checkGroup);
//
//        return new Result(true);
//    }
    @PostMapping("addGroup")
    public Result addGroup(@RequestBody CheckGroupDto checkGroupDto){
        System.out.println(checkGroupDto.getCheckitemIds());
        System.out.println("checkGroup = " + checkGroupDto);
        checkGroupService.addGroup(checkGroupDto);
        return new Result(true);
    }
    @PostMapping("/findAllGroupByPage")
    public PageResult findAllGroupByPage(@RequestBody QueryPageBean queryPageBean){
        System.out.println("queryPageBean = " + queryPageBean);
        PageResult pageResult = checkGroupService.findAllGroupByPage(queryPageBean);
        return pageResult;
    }
    @GetMapping("findAll")
    public List<CheckGroup> findAll(){
        List<CheckGroup> list=checkGroupService.findAll();
        return list;
    }
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        System.out.println("id = " + id);
       checkGroupService.deleteById(id);
      return new Result(true);
    }
}
